package com.zf.yichat.controller.report;

import com.github.pagehelper.PageHelper;
import com.zf.yichat.controller.BaseController;
import com.zf.yichat.mapper.ReportMapper;
import com.zf.yichat.mapper.UserReportMapper;
import com.zf.yichat.model.User;
import com.zf.yichat.model.UserReport;
import com.zf.yichat.utils.common.DtoChangeUtils;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Controller
@RequestMapping("report")
public class ReportController  extends BaseController {
    @Autowired
    private UserReportMapper userReportMapper;
    @Autowired
    private ReportMapper reportMapper;

    @RequestMapping("index")
    public String index() {
        return "report/index";
    }

    @RequestMapping("/list")
    @ResponseBody
    public FsResponse list(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return DtoChangeUtils.getPageList(reportMapper.selectList(), v -> v);
    }


    @RequestMapping("/delete")
    @ResponseBody
    public FsResponse delete(Integer id) {

        UserReport report = new UserReport();
        report.setStatus(1);
        Example select=new Example(UserReport.class);
        select.createCriteria().andEqualTo("id",id);
        userReportMapper.updateByExampleSelective(report,select);
        return FsResponseGen.success();
    }

}
